package mx.edu.itschapala.sistemas.septimo.vista;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import mx.edu.itschapala.sistemas.septimo.control.ProductoLnLocal;
import mx.edu.itschapala.sistemas.septimo.modelo.Producto;
import mx.edu.itschapala.sistemas.septimo.vista.enumeracion.TipoBusqueda;

/**
 *
 * @author snake_gt
 */
public class ProductoListar extends javax.swing.JFrame {

    private final ProductoLnLocal productoControl;
    private DefaultTableModel modelo;
    private List<Producto> lista;

    /**
     * Creates new form ProductoListar
     */
    public ProductoListar(ProductoLnLocal productoControl) {
        this.productoControl = productoControl;
        initComponents();
        String nombres[] = {"Codigo", "Nombre", "Precio", "Departamento", "Descripcion"};
        modelo = new DefaultTableModel(nombres, 0);
        jTable2.setModel(modelo);
        for (Producto p : productoControl.getTodos()) {
            String renglon[] = new String[5];
            renglon[0] = p.getCodigo() + "";
            renglon[1] = p.getNombre();
            renglon[2] = p.getPrecio() + "";
            renglon[3] = p.getDepartamento();
            renglon[4] = p.getDescripcion();
            modelo.addRow(renglon);
        }
        jTable2.setModel(modelo);
        lista = tmp;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jRadioButton4 = new javax.swing.JRadioButton();
        jTextField2 = new javax.swing.JTextField();
        jRadioButton3 = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel2.setLayout(new java.awt.GridLayout(2, 2));

        jRadioButton4.setText("Contiene");
        jPanel2.add(jRadioButton4);

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jPanel2.add(jTextField2);

        jRadioButton3.setText("inicia");
        jPanel2.add(jRadioButton3);

        jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 20, 390, 60));

        jPanel3.setLayout(new java.awt.GridLayout(1, 0));

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jPanel3.add(jScrollPane2);

        jPanel1.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 120, 520, 220));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 522, 431));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
        if(evt.getClickCount()==2){
            Producto p = lista.get(jTable2SelectedRow(modelo));
            lista=productoControl.getTodos();
            Dialogo d = new Dialogo();
            d.setVisible(true);
        }
    }//GEN-LAST:event_jTable2MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}
